package com.burgeon.backend.SHOP.controller;


import com.burgeon.backend.SHOP.service.SystemService;
import com.burgeon.backend.entity.Wechat;
import com.burgeon.backend.mappers.WechatMapper;
import com.burgeon.backend.service.ex.ErrorDataException;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("shop/sys")
@RestController
public class SystemController extends BaseController{
    @Autowired
    private SystemService systemService;
    @Autowired
    private WechatMapper wechatMapper;

    @RequestMapping("test")
    public void Test(String data) {
        System.err.println("*******************************************");
        System.err.println(data);
    }


    @RequestMapping("test1")
    public ResponseResult<Wechat> Test1(String token) {
        Wechat data = wechatMapper.getWechat(token);
        if (data == null) {
            throw new ErrorDataException("获取数据错误");
        }
        data.setResponseType("code");
        data.setScope("snsapi_base");
        System.err.println("wechat=="+data);
        return new ResponseResult<Wechat>(SUCCESS,data);
    }



    @RequestMapping("template")
    public ResponseResult<List<String>> FindOrder(HttpSession session) {
        String token = session.getAttribute("token").toString();
        List<String> data = systemService.getTemplate(token);
        return new ResponseResult<List<String>>(SUCCESS,data);
    }
}
